Repository navigation
feat(lk): read evals and eval results under --user-auth - #1152
Conversation
Picks up the Public API's project-level observability reads: ListProjectLogs, ListLogPatterns and GetAgentInsights. Nothing calls them yet. Also picks up what the spec gained since the last regeneration: the eval and session label RPCs, GetSessionEvals, ListEvalSessions, GetEvalResults, GetSessionLabelResults, and Agent Builder, whose service is now AgentBuilderService in place of BuilderAgentService. Nothing in lk calls them. Generated from livekit/public-api-server@16e4400
Reads the Public API's ListProjectLogs: the log records that the logs page on the dashboard lists, from the project's agents, client SDKs and LiveKit, newest first, one line per record with its time, level, source, session, logger and message. --json prints the records as the API sends them. --since, or --start and --end (a UTC date or an RFC 3339 time), set the range; without them the server reads the last 24 hours. --log-level, --source, --session-id and --query filter, --sort-order orders, and --limit and the hidden --cursor page, as for lk analytics session logs. The read is for project admins. A refusal says so, a query the server can't parse gets a hint about the search syntax (an attribute needs its @), and with user data recording off the error names the settings page, as the session reads do.
Reads the Public API's ListLogPatterns: the patterns that the logs page on the dashboard groups a project's log records into, ranked, one row each with its number of records, level, source, first and last record, and template. A note on stderr says how many records the range holds and, on a project with many records, that the counts are estimates. --json prints the API's response, with each pattern's counts over time and its variants. It takes the same range flags as lk analytics logs, plus --min-level (the server's default is WARN), --source agent|client, --agent-name, --agent-id, --session-id, --query, --rank events|first-seen|last-seen and --limit. The list is one page, so there is no --cursor. The read is for project admins, and its errors say so as the logs' do.
Reads the Public API's GetAgentInsights: the data that the agent dashboards of LiveKit Cloud show, as four tables. The totals; the latencies that have measurements (end-to-end, LLM and realtime time to first token, TTS time to first byte, transcription and end-of-utterance delay, tool calls) with p50, p95, p99, mean and max; one row for each agent and deployment, busiest first; and one row for each model, with its tokens, characters or seconds of audio. --json prints the API's response. It takes the same range flags as lk analytics logs, reading the last 7 days by default, and --agent-id and --agent-name, repeatable, to select agents. Every project member can read it, so a refusal says the caller has no access to the project rather than that it needs an admin.
- A project read's refusal now goes through readAPIError, which sessionAPIError also calls, so the two no longer repeat the same permission-denied wording. - The help says that a lone --end moves the range too: each read covers its default length before --end. It also says that times print in local time. - The hint for a query the server can't parse no longer says that a missing @ is the only cause. - logs' usage line lists --sort-order and --limit, and --source's help gives a participant joining as its platform example, the proto's own example. - log-patterns prints "1 pattern shown", not "1 patterns". - insights prints a dash for an STT's requests, which the API always counts as 0.
Adds client calls for the Public API's eval reads: ListEvals, GetEval, ListEvalHistory, DiffEvalRevisions, GetEvalDefaults, ListSessionLabels, GetSessionLabelSettings, GetEvalResults, GetSessionLabelResults, ListEvalSessions and GetSessionEvals, with their renderers. GetEval and GetEvalDefaults keep the definition as the API sent it: the generated type drops unknown properties and stores pass_threshold as a float32. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lk agent eval list|get|history|diff|defaults and lk agent eval label list|settings read a project's evals and session labels. lk analytics evals|eval-sessions|labels and lk analytics session evals read their results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Six agent dev tests left devSession.run running after they returned. It prints through the shared out, so it raced with the next test that replaced out; the new agent_eval_test.go sorts right after them and tripped -race. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Print the reason on its own lines wrapped at 80 columns and the transcript excerpt quoted with "> " as written, not Go-quoted. Leave "on -" out of an eval heading when the session has no agent name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The eval sessions response carries only the label IDs, so read the project's labels (deleted ones included) once and show each label by name. A failed label read falls back to the IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lk analytics eval-sessions reads the project's evals once and shows each eval by name, cut to 30 characters, falling back to the ID. lk analytics session evals prints a blank line between one eval's failures and the next eval. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A flag given with a blank ID used to read every session, as if it were left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Topherhindman
left a comment
There was a problem hiding this comment.
took a pass at cbfb3f5, looks good and follows the analytics patterns. couple of nits inline. on the body: the bare #212/#213/#216/#219 link to livekit-cli PRs here, they want livekit/public-api-server#N, and "merge #1146 first" is stale now that it's in (rebase onto main is one small conflict in the script_test route table). golangci-lint is clean too fwiw
| // Like projectRead's, the action refuses to run without --user-auth before | ||
| // checking anything else, then reads the EVAL_ID argument and the command's | ||
| // options, so a bad flag fails before the project lookup. | ||
| func evalRead[O any]( |
There was a problem hiding this comment.
this is sessionRead with "eval ID" in the error. could sessionRead take the id name (the actionWithID shape from #1153) so there's just one?
There was a problem hiding this comment.
Done in ee4ff4f: one actionWithID(idName, …); sessionRead and evalAction wrap it.
| Name: "eval-sessions", | ||
| Usage: "List the sessions that a project's evals scored, with their verdicts (requires --user-auth)", | ||
| UsageText: "lk analytics eval-sessions [--since DURATION | --start TIME [--end TIME]] [--eval-id EVAL_ID " + | ||
| "[--verdict VERDICT | --criterion-id ID]] [--agent-name NAME ...] [--intent-id ID ...] [--outcome-id ID ...] " + |
There was a problem hiding this comment.
nit: this nests --verdict under --eval-id, but --verdict works on its own (the description says so too). only --criterion-id needs --eval-id
| Usage: "Print only the sessions in which the eval in --eval-id failed the criterion `ID`; can't be used with --verdict", | ||
| }, | ||
| &cli.StringSliceFlag{ | ||
| Name: "agent-name", |
There was a problem hiding this comment.
nit: agent-name / intent-id / outcome-id here are the same three flags as evalFilterFlags. one helper for both?
There was a problem hiding this comment.
Done in ee4ff4f: both use sessionFilterFlags().
| criterionID := strings.TrimSpace(opts.CriterionID) | ||
| if criterionID != "" { | ||
| if evalID == "" { | ||
| return nil, fmt.Errorf("a criterion needs the eval it belongs to") |
There was a problem hiding this comment.
the server already refuses a criterionId without an evalId or with a verdict. do we need our own copy of that rule? the enum parsing makes sense here, this feels like it'll drift
There was a problem hiding this comment.
Agreed, dropped in ee4ff4f. Enum parsing stays.
…eads # Conflicts: # cmd/lk/analytics.go # cmd/lk/analytics_project.go # cmd/lk/analytics_project_test.go # cmd/lk/script_test.go # pkg/public/project_logs.go # pkg/public/project_logs_test.go
- sessionRead and evalAction share one actionWithID, which takes the ID's name. - eval-sessions and the eval results reads share the agent, intent and outcome filter flags. - Drop the client's copy of the criterion rules; the API refuses a criterion without its eval or with a verdict. - The eval-sessions usage shows --verdict works without --eval-id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Lets a person or coding agent signed in with
--user-authread a project's evals and their results fromlk. An eval is a set of criteria that LiveKit checks on each finished live session; a session label is the intent or outcome an LLM assigns to each session.lk agent eval list | get EVAL_ID [--revision N | --draft] | history | diff --from V --to V | defaultslk agent eval label list [--kind intent|outcome] | settingslk analytics evals: pass/fail/undecided counts per eval, version, criterion, agent and error code (GetEvalResults, READ)lk analytics labels: sessions per intent/outcome, intent → outcome pairs, failed share per label (GetSessionLabelResults, READ)lk analytics eval-sessions(--eval-id,--verdict,--criterion-id, paged) andlk analytics session evals RM_ID: per-session verdicts, criteria, judge answers and failure reasons (ADMIN)Why
The Public API serves evals in production (livekit/public-api-server#211, livekit/public-api-server#212, livekit/public-api-server#213, livekit/public-api-server#216, livekit/public-api-server#219), and the MCP has them as tools, but
lkhad no commands for them.How
lk analyticsand reuseprojectRead,timeRangeFlags,readPagesand the empty-read / 403 messages. Session and eval commands share oneactionWithID. Definitions and labels live underlk agent eval, besidelk agent simulate. It is hidden until a user signs in, like the other Public-API-only groups.getanddefaultsdecode the definition as raw JSON. The generated type drops unknown properties and storespass_thresholdas a float32, soget --jsonwould otherwise not round-trip. PR 2 relies on this for edits.--intent-id/--outcome-idtakeLBL_…,other, orunlabeled. The API spellsunlabeledas an empty string, which is awkward to pass on a command line.--criterion-idneeding--eval-id.eval-sessionsshows intents, outcomes and evals by name, with one extra read each, since its response carries only the IDs.Writes (create/validate/publish/rollback/delete, label CRUD, settings) follow in a stacked PR.
Testing
go build ./...,go vet ./...,go test ./...andgo test -race ./cmd/lk ./pkg/public/...pass. The race run needed a test fix: sixagent_dev_test.gotests leftdevSession.runprinting through the sharedoutafter they returned, and the newagent_eval_test.gosorts right after them. They now wait for it to stop.--jsonoutput, empty reads, and 403/404 messages.eval-reads-with-user-auth.txtarruns the built binary against the fake Public API. Each canned body decodes strictly into the generated type, and each query is matched exactly.golangci-lintis clean (run in review).list,get,diff,eval-sessionsandsession evals.🤖 Generated with Claude Code